<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://www.petercorke.com/RVC/common/toolboxhelp.css">
    <title>M-File Help: colorkmeans</title>
  </head>
  <body>
  <table border="0" cellspacing="0" width="100%">
    <tr class="subheader">
      <td class="headertitle">M-File Help: colorkmeans</td>
      <td class="subheader-left"><a href="matlab:open colorkmeans">View code for colorkmeans</a></td>
    </tr>
  </table>
<h1>colorkmeans</h1><p><span class="helptopic">Color image segmentation by clustering</span></p><strong>L</strong> = <span style="color:red>colorkmeans</span>(<strong>im</strong>, <strong>k</strong>, <strong>options</strong>) is a segmentation of the color image <strong>im</strong>
into <strong>k</strong> classes.  The label image <strong>L</strong> has the same row and column dimension
as <strong>im</strong> and each pixel has a value in the range 0 to <strong>k</strong>-1 which indicates
which cluster the corresponding pixel belongs to.  A k-means clustering of
the chromaticity of all input pixels is performed.

[<strong>L</strong>,<strong>C</strong>] = <span style="color:red>colorkmeans</span>(<strong>im</strong>, <strong>k</strong>) as above but also returns the cluster
centres <strong>C</strong> (Kx2) where the I'th row is the rg-chromaticity of the I'th
cluster and corresponds to the label I.  A k-means clustering of the
chromaticity of all input pixels is performed.

[<strong>L</strong>,<strong>C</strong>,<strong>R</strong>] = <span style="color:red>colorkmeans</span>(<strong>im</strong>, <strong>k</strong>) as above but also returns the residual <strong>R</strong>, the
root mean square error of all pixel chromaticities with respect to their
cluster centre.

<strong>L</strong> = <span style="color:red>colorkmeans</span>(<strong>im</strong>, <strong>C</strong>) is a segmentation of the color image <strong>im</strong> into <strong>k</strong> classes
which are defined by the cluster centres <strong>C</strong> (Kx2) in chromaticity space.
Pixels are assigned to the closest (Euclidean) centre.  Since cluster
centres are provided the k-means segmentation step is not required.

<h2>Options</h2>
Various options are possible to choose the initial cluster centres
for k-means:

<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> 'random'</td> <td>randomly choose K points from</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> 'spread'</td> <td>randomly choose K values within the rectangle spanned by the
input chromaticities.</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> 'pick'</td> <td>interactively pick cluster centres</td></tr>
</table>
<h2>Notes</h2>
<ul>
  <li>The k-means clustering algorithm used in the first three forms is
computationally expensive and time consuming.</li>
  <li>Clustering is performed in rg-chromaticity space.</li>
  <li>The residual is an indication of quality of fit, low is good.</li>
</ul>
See also

<hr>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr class="subheader" valign="top"><td>&nbsp;</td></tr></table>
<p class="copy">&copy; 1990-2011 Peter Corke.</p>
</body></html>